/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cansniffer;

/**
 *
 * @author PiotrGl
 */
class MCP2510 {

    public static int BFPCTRL = 0x0C;
    public static int TXRTSCTRL = 0x0D;
    public static int CANSTAT = 0x0E;
    public static int CANCTRL = 0x0F;
    public static int TEC = 0x1C;
    public static int REC = 0x1D;
    public static int CNF3 = 0x28;
    public static int CNF2 = 0x29;
    public static int CNF1 = 0x2A;
    public static int CANINTE = 0x2B;
    public static int CANINTF = 0x2C;
    public static int EFLG = 0x2D;
    public static int TXB0CTRL = 0x30;
    public static int TXB1CTRL = 0x40; 
    public static int TXB2CTRL = 0x50;
    public static int RXB0CTRL = 0x60; 
    public static int RXB1CTRL = 0x70;
   
    static {
        System.load("/home/sasza/NetBeansProjects/CANsniffer-C/dist/Debug/GNU-Linux-x86/libCANsniffer-C.so");
    }
    
    private native int[] nativePrint(int liczba, int[] liczby);
    private native void mainly();
    
    public MCP2510() {
        //System.out.println(System.getProperty("java.library.path"));
        //System.setProperty("java.library.path", System.getProperty("java.library.path")+":/home/sasza/NetBeansProjects/CANsniffer-C/dist/Debug/GNU-Linux-x86/");
        //System.out.println(System.getProperty("java.library.path"));
    }
       
    //zwraca status
    public int ReadStatus(){
        //0x0A 0xff
        //read:
        //0CANINTF.RX0IF
        //1CANINTF.RX1IF
        //2TXB0CNTRL.TXREQ
        //3CANINTF.TX0IF
        //4TXB1CNTRL.TXREQ
        //5CANINTF.TX1IF
        //6TXB2CNTRL.TXREQ
        //7CANINTF.TX2IF
        
        
        
        return 1;
    }
       
    public void RequestToSend(boolean TXB2, boolean TXB1, boolean TXB0){
        //0b1000 0 TXB2 TXB1 TXB0
    }
    
    //czyta jeden bajt z pod adresu
    public int Read(int adress){
        //0x03 adress 0xFF
        return 0x55;
    }
    
    //czyta bajty od adress 
    public int[] Read(int adress, int len){
        //0x03 adress 0xFF[len]
        int odczytane[]={0,1};
        
        return odczytane;
    }
    
    //zapis jednego bajtu z pod adresu
    public void Write(int adress, int data){
        //0x02 adress data
    }
    
    //zapis kilku bajtów od adress 
    public void Write(int adress, int data[]){
        //0x02 adress data[]
    }
        
    //
    public void Write(int adress, int data, int mask){
        //0x05 adress mask data

        int ret[]={0};
        int a[] = {2,3,4,5,6};
        try {
        ret = new MCP2510().nativePrint(5, a);
        
        } catch (Exception e){
            System.out.println(e);
        }
        System.out.println("ret: "+ret[0]);
        System.out.println(adress+": "+(data&mask));
    }
    
    public void Reset(){
        //0xC0
    }
    
    public void testGPIO(){
        mainly();
    };
    
}
